package com.xw.unification.interceptor;

import com.xw.unification.config.WebUnificationMvcProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统一请求拦截器
 * @author qiwei
 */
public interface UnifiedRequestInterceptor {
    default boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler,
                              ApplicationContext ctx, WebUnificationMvcProperties properties)
            throws Exception {

        return true;
    }

    default void postHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler,
                            ApplicationContext ctx, WebUnificationMvcProperties properties,
                            @Nullable ModelAndView modelAndView) throws Exception {
    }

    default void afterCompletion(HttpServletRequest request, HttpServletResponse response, HandlerMethod handler,
                                 ApplicationContext ctx, WebUnificationMvcProperties properties,
                                 @Nullable Exception ex) throws Exception {
    }
}
